package com.zhengke.service.directory;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zhengke.common.object.ZTreeNode;
import com.zhengke.dao.SysDictionaryDao;
import com.zhengke.pojo.SysDictionary;
import com.zhengke.pojo.SysDictionaryItem;
@Service
public class SysDictionaryServiceImpl implements SysDictionaryService {

	@Autowired
	SysDictionaryDao sysDao;
	@Override
	public List<ZTreeNode> queryDic() {
		List<SysDictionary> list = sysDao.queryDic();
		System.out.println(list);
		List<ZTreeNode> rtnList = new ArrayList<ZTreeNode>();
		for(SysDictionary dict:list) {
			ZTreeNode node = new ZTreeNode();
			node.setId(dict.getDicId());
			node.setName(dict.getDicName());
			node.setIsParent(true);
			rtnList.add(node);
		}
		
		return rtnList;
	}
	@Override
	public List<ZTreeNode> querySlaveNodes(String id) {
		List<ZTreeNode> rtnList =new ArrayList<ZTreeNode>();
		List<SysDictionaryItem> list = sysDao.querySlaveNodes(id);
		if(list!=null) {
			for(SysDictionaryItem dict:list) {
				ZTreeNode node = new ZTreeNode();
				node.setId(dict.getItemId());
				node.setName(dict.getParamName());
				node.setIsParent(false);
				rtnList.add(node);
			}
		}
		
		return rtnList;
	}
	@Override
	public int insert(SysDictionary dic) {
		return sysDao.insert(dic);
	}
	@Override
	public int insertSub(SysDictionaryItem dicItem) {
	
		return sysDao.insertSub(dicItem);
	}
	
	@Override
	public int delDicItemByItemId(String itemId) {
		return 	sysDao.delDicItemByItemId(itemId);
	}
	@Override
	public int delDicBydicId(String dicId) {
		return sysDao.delDicBydicId(dicId);
	}
	@Override
	public int updateDicSubClass(SysDictionaryItem dicItem) {

		return 	sysDao.updateDicSubClass(dicItem);
	}
	@Override
	public int updateDicClass(SysDictionary dic) {
		return sysDao.updateDicClass(dic);
	}

	@Override
	public String queryParamValue() {
		return sysDao.queryParamValue();
	}

}
